<?php

namespace common\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\CepingSubject;

/**
 * CepingSubjectSearch represents the model behind the search form about `common\models\CepingSubject`.
 */
class CepingSubjectSearch extends CepingSubject
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['label_id', 'label_name', 'parent_id', 'foreign_id', 'label', 'paperId', 'res1', 'res2', 'res3'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class 
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CepingSubject::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1'); 
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'label_id', $this->label_id])
            ->andFilterWhere(['like', 'label_name', $this->label_name])
            ->andFilterWhere(['like', 'parent_id', $this->parent_id])
            ->andFilterWhere(['like', 'foreign_id', $this->foreign_id])
            ->andFilterWhere(['like', 'label', $this->label])
            ->andFilterWhere(['like', 'paperId', $this->paperId])
            ->andFilterWhere(['like', 'res1', $this->res1])
            ->andFilterWhere(['like', 'res2', $this->res2])
            ->andFilterWhere(['like', 'res3', $this->res3]);

        return $dataProvider;
    }
} 